package com.aistar.line.controller;

import com.aistar.common.vo.Result;
import com.aistar.common.vo.StatusCode;
import com.aistar.line.entity.Collect;
import com.aistar.line.entity.Line;
import com.aistar.line.service.ILineService;
import com.aistar.line.vo.LineSpotHotel;
import com.aistar.line.vo.Reserve;
import com.aistar.line.vo.Screen;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Description: java类作用描述:
 * @Author: tyg
 * @CreateDate: 2019/6/25 0025
 * @Version: 1.0
 */
@RestController
public class LineController {
    @Autowired
    private ILineService lineService;

    /**
     * 旅游路线浏览展示的信息
     *
     * @return
     */
    @PostMapping("/line")
    public Result lineFind(@RequestBody Screen screen) {

        PageInfo<LineSpotHotel> info = lineService.getPageInfo(screen);

        Result result = new Result(true, StatusCode.OK, "查询路线产品信息", info);

        return result;
    }

    /**
     * 旅游路线所有详情信息
     *
     * @param line
     * @return
     */
    @GetMapping("/linedetail/{lineId}")
    public Result detailFind(Line line) {
        LineSpotHotel lineSpotHotel = lineService.findById(line);

        Result result = new Result(true, StatusCode.OK, "查询路线详情", lineSpotHotel);

        return result;
    }

    /**
     * 热卖产品展示信息
     *
     * @param line
     * @return
     */
    @GetMapping("/line/{lineEnd}")
    public Result ranking(Line line) {
        System.out.println(line.getLineEnd());
        List<LineSpotHotel> list = lineService.rankingBySuccess(line);
        System.out.println(list);
        Result result = new Result(true, StatusCode.OK, "查询热卖路线详情", list);

        return result;
    }

    /**
     * 验证用户是否收藏
     *
     * @param collect
     * @return
     */
    @GetMapping("/linecollect/{lineId}")
    public Result collect(Collect collect) {
        if (lineService.collect(collect)) {
            return new Result(true, StatusCode.OK, "用户已收藏");
        } else {
            return new Result(true, StatusCode.ERROR, "用户未收藏");
        }
    }

    /**
     * 添加收藏
     *
     * @param collect
     * @return
     */
    @PostMapping("/linecollect")
    public Result addcollect(Collect collect) {
        if (lineService.addCollect(collect)) {
            return new Result(true, StatusCode.OK, "添加收藏成功");
        } else {
            return new Result(true, StatusCode.ERROR, "添加收藏失败");
        }
    }

    /**
     * 取消收藏
     *
     * @param collect
     * @return
     */
    @DeleteMapping("/linecollect/{lineId}")
    public Result delcollect(Collect collect) {
        if (lineService.delCollect(collect)) {
            return new Result(true, StatusCode.OK, "取消收藏成功");
        } else {
            return new Result(true, StatusCode.ERROR, "取消收藏失败");
        }
    }

    /**
     * 每次预定商品保存完成预定前的信息
     *
     * @param reserve
     * @return
     */
    @PostMapping("/linedetail")
    public Result addReserve(Reserve reserve) {
        System.out.println(reserve);
        if (lineService.addReserve(reserve)) {
            return new Result(true, StatusCode.OK, "保存预定信息成功");
        } else {
            return new Result(true, StatusCode.ERROR, "保存预定信息失败");
        }
    }


}
